<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="统计模块" prop="modularType"
                :rules="[
                  {required: true, message:'统计模块不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.modularType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('modular_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="内部表ID" prop="keyId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.keyId" placeholder="请填写内部表ID"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="停留时间" prop="totalTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalTime" placeholder="请填写停留时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="导视设备" prop="kioskId"
                :rules="[
                  {required: true, message:'导视设备不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.kioskId" placeholder="请填写导视设备"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.startTime" placeholder="请填写开始时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.endTime" placeholder="请填写结束时间"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          modularType: '',
          keyId: '',
          totalTime: '',
          kioskId: '',
          startTime: '',
          endTime: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建统计时间`
        } else if (method === 'edit') {
          this.title = '修改统计时间'
        } else if (method === 'view') {
          this.title = '查看统计时间'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/smis/tongji/jfKioskTongjiTime/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.jfKioskTongjiTime)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/smis/tongji/jfKioskTongjiTime/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>